package threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author sesshomaru
 * @date 2021/10/12 20:44
 */
public class Shutdown {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            fixedThreadPool.execute(new ShutdownTask());
        }
        Thread.sleep(1500);
      /*  System.out.println("当前线程池是否进入停止状态: " + fixedThreadPool.isShutdown());
        System.out.println("-------------------------------------------------------------------开始关闭线程池-------------------------------------------------------------------");
        fixedThreadPool.shutdown();
        System.out.println("当前线程池是否进入停止状态: " + fixedThreadPool.isShutdown());
        Thread.sleep(10000);
        System.out.println("线程池是否真正关闭: " + fixedThreadPool.isTerminated());*/

        fixedThreadPool.shutdownNow();

    }
}

class ShutdownTask implements Runnable{
    @Override
    public void run() {
        try {
            Thread.sleep(500);
            System.out.println(Thread.currentThread().getName());
            // 当前线程任务还在运行，然后被突然中断就会走到异常里面
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName() + "线程被中断");
        }
    }
}
